package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Bank.DebugListener;
import com.acme.bankapp.domain.bank.Bank.EmailNotificationListener;
import com.acme.bankapp.domain.bank.Bank.PrintClientListener;
import com.acme.mock.BankServer;

public class BankApplication {
	private static String feedPath;

	public static void main(String[] args) {
		ClientRegistrationListener[] listeners = clientRegistrationListenersCreator();

		Bank bank = new Bank(listeners);

		for (int i = 0; i < args.length; i++) {
			if ("-loadfeed".equals(args[i])) {
				feedPath = args[++i];
			}
			if ("-loadbank".equals(args[i])) {
				BankService.SAVE_BANK_PATH = args[++i];
			}
			if ("-server".equals(args[i])){
				BankServer.startServer(bank);
			}
		}

		BankService.printBalance(bank);
		if (feedPath != null) {
			BankService.loadFeedData(bank, feedPath);
		}

	}

	private static ClientRegistrationListener[] clientRegistrationListenersCreator() {
		return new ClientRegistrationListener[] { new DebugListener(),
				new EmailNotificationListener(), new PrintClientListener() };
	}

}
